package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BizSeller;
import com.ruoyi.business.service.IBizSellerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商户申请Controller
 * 
 * @author ruoyi
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/business/seller")
public class BizSellerController extends BaseController
{
    @Autowired
    private IBizSellerService bizSellerService;

    /**
     * 查询商户申请列表
     */
    @PreAuthorize("@ss.hasPermi('business:seller:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizSeller bizSeller)
    {
        startPage();
        List<BizSeller> list = bizSellerService.selectBizSellerList(bizSeller);
        return getDataTable(list);
    }

    /**
     * 导出商户申请列表
     */
    @PreAuthorize("@ss.hasPermi('business:seller:export')")
    @Log(title = "商户申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizSeller bizSeller)
    {
        List<BizSeller> list = bizSellerService.selectBizSellerList(bizSeller);
        ExcelUtil<BizSeller> util = new ExcelUtil<BizSeller>(BizSeller.class);
        util.exportExcel(response, list, "商户申请数据");
    }

    /**
     * 获取商户申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:seller:query')")
    @GetMapping(value = "/{sellerId}")
    public AjaxResult getInfo(@PathVariable("sellerId") Long sellerId)
    {
        return success(bizSellerService.selectBizSellerBySellerId(sellerId));
    }

    /**
     * 新增商户申请
     */
    @PreAuthorize("@ss.hasPermi('business:seller:add')")
    @Log(title = "商户申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizSeller bizSeller)
    {
        bizSeller.setCreateBy(getUsername());
        return toAjax(bizSellerService.insertBizSeller(bizSeller));
    }

    /**
     * 修改商户申请
     */
    @PreAuthorize("@ss.hasPermi('business:seller:edit')")
    @Log(title = "商户申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizSeller bizSeller)
    {
        bizSeller.setUpdateBy(getUsername());
        return toAjax(bizSellerService.updateBizSeller(bizSeller));
    }
    @PreAuthorize("@ss.hasPermi('business:seller:isTop')")
    @Log(title = "商户置顶", businessType = BusinessType.UPDATE)
    @PutMapping("/sellerTop")
    public AjaxResult sellerTop(@RequestBody BizSeller bizSeller)
    {
        bizSeller.setUpdateBy(getUsername());
        return toAjax(bizSellerService.sellerTop(bizSeller));
    }
    @PreAuthorize("@ss.hasPermi('business:seller:isTop')")
    @Log(title = "商户置顶", businessType = BusinessType.UPDATE)
    @PutMapping("/sellerCancelTop")
    public AjaxResult sellerCancelTop(@RequestBody BizSeller bizSeller)
    {
        bizSeller.setUpdateBy(getUsername());
        return toAjax(bizSellerService.updateBizSeller(bizSeller));
    }


    @PreAuthorize("@ss.hasPermi('business:seller:edit')")
    @Log(title = "商户申请", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BizSeller bizSeller)
    {
        bizSeller.setUpdateBy(getUsername());
        return toAjax(bizSellerService.updateBizSeller(bizSeller));
    }

    /**
     * 删除商户申请
     */
    @PreAuthorize("@ss.hasPermi('business:seller:remove')")
    @Log(title = "商户申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sellerIds}")
    public AjaxResult remove(@PathVariable Long[] sellerIds)
    {
        return toAjax(bizSellerService.deleteBizSellerBySellerIds(sellerIds));
    }
}
